package org.tpdata.api;

import asserts.Asserts;
import utils.Contants;
import com.alibaba.fastjson.JSONObject;
import common.SetUpTearDown;
import common.RunCaseJson;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;

import static common.TestStep.requestAndRespondBody;


@Feature("登录")
public class login extends SetUpTearDown {
    Logger log = Logger.getLogger(login.class);

    @Story("登录正确")

  @Test(description = "登录测试")

    public  void runCase()  {
        JSONObject json= new JSONObject();
        json.put("userName", "112");
        json.put("passwd", "tP123456@");
        json.put("orgId", "75635");

        Response response=RunCaseJson.runCase(json,"post","api-auth/login");
        String jsonStr= response.asString();
        log.info("响应报文："+jsonStr);
//        log.info(response.jsonPath().get());

//        Assert.assertEquals(response.getStatusCode(),200);
//        JsonPath jsonPath=response.jsonPath();
//        String response_data=jsonPath.get("msg").toString();

        JSONObject obj = JSONObject.parseObject(jsonStr);
        JSONObject data= obj.getJSONObject("data");
        String realName=data.getString("realName");
        String url = RestAssured.baseURI + ":" + RestAssured.port + "/" + RestAssured.basePath + "/api-auth/login";
        requestAndRespondBody(url,json,jsonStr);
        Boolean flag=Asserts.VerityString(realName,"abc");
        Assert.assertEquals(flag, Contants.ASSERT_SUCCESS);
    }

/*
    @Attachment("响应报文")
    public static String respondBody(String respond) {
        //格式化json串
        boolean prettyFormat = true; //格式化输出
        JSONObject jsonObject = JSONObject.parseObject(respond);

        String str = JSONObject.toJSONString(jsonObject,prettyFormat);

        //报告展现响应报文
        return str;
    }

    @Attachment("请求报文")
    public static String requestBody1(String URL, JSONObject body) {

        //格式化json串
        boolean prettyFormat = true; //格式化输出
        String str = JSONObject.toJSONString(body,prettyFormat);

        //报告展现请求报文
        return URL+"\n"+str;
    }


    public static void requestAndRespondBody(String URL, JSONObject Body,String Respond){
        requestBody1(URL,Body);
        respondBody(Respond);
    }
*/

}
